package org.beetl.support;

import java.util.ArrayList;
import java.util.List;

/**
 * 表单提交结果.
 * 
 * @author zhoupan.
 * 
 */
public class FormResultSupport extends ResultSupport {

 /**
 * 
 */
 private static final long serialVersionUID = 1L;

 /**
  * 错误消息列表.
  */
 private List<Message> fieldMessages = new ArrayList<Message>();
 private List<Message> globalMessages = new ArrayList<Message>();

 public void onField(Message msg) {
  this.fieldMessages.add(msg);
 }

 public void onGlobal(Message message) {
  this.globalMessages.add(message);
 }

 public List<Message> getFieldMessages() {
  return fieldMessages;
 }

 public void setFieldMessages(List<Message> fieldMessages) {
  this.fieldMessages = fieldMessages;
 }

 public List<Message> getGlobalMessages() {
  return globalMessages;
 }

 public void setGlobalMessages(List<Message> globalMessages) {
  this.globalMessages = globalMessages;
 }

 public boolean hasFieldError() {
  for (Message message : this.fieldMessages) {
   if (message.isError()) {
    return true;
   }
  }
  return false;
 }

 public boolean hasGlobalError() {
  for (Message message : this.globalMessages) {
   if (message.isError()) {
    return true;
   }
  }
  return false;
 }

 public boolean hasError() {
  return this.hasFieldError() || this.hasGlobalError();
 }

}
